package com.doit.day02

import scala.io.Source

object _03_wordCount练习 {
  def main(args: Array[String]): Unit = {
    //读文件
    val lines: Iterator[String] = Source.fromFile("data/input/word.txt").getLines()
    //list中放的就是一行一行的句子
    //hello,hi,hi,hello,hive,hive,hadoop,hadoop,hbase
    val list: List[String] = lines.toList


    //做word count 会不会？？？？
    //先flatMap
    val words: List[String] = list.flatMap((line: String) => {
      line.split(",")
    })

    val grouped: Map[String, List[String]] = words.groupBy((word: String) => word)

//    元祖
    val res: Map[String, Int] = grouped.map(tp => {
      val key: String = tp._1
      val value: List[String] = tp._2
      val size: Int = value.size
      (key, size)
    })

    println(res)

  }

}
